﻿@{
    ViewBag.Title = "数据权限编辑";
    Layout = null;
}
<style>
    input[type="checkbox"] {
        border: 1px solid #C6C6C6;
        outline: none;
    }

    .button {
        border-radius: 0px;
    }

    .mainbody {
        padding: 0px;
    }
    /*自定义复选框*/
    .ScrollBar {
        background: none repeat scroll 0 0 #fff;
        overflow: auto;
    }

    .sys_spec_text {
        padding-left: 15px;
    }

        .sys_spec_text li {
            display: inline;
            float: left;
            height: 43px;
            margin: 10px 15px 0px 0;
            outline: none;
            outline: none;
            position: relative;
            position: relative;
        }

            .sys_spec_text li a {
                background: #fff;
                border: 1px solid #ccc;
                border-radius: 5px 5px 5px 5px;
                cursor: pointer;
                display: inline-block;
                line-height: 39px;
                outline: none;
                overflow: hidden;
                padding: 0px 0px;
                text-align: center;
                text-align: center;
                text-overflow: ellipsis;
                vertical-align: middle;
                white-space: nowrap;
                width: 98px;
                word-break: keep-all;
            }

                .sys_spec_text li a:hover {
                    border: 1px solid #4A5B79;
                    padding: 0 0px;
                    text-decoration: none;
                }

            .sys_spec_text li .check {
                background: url(/Contents/images/edit/sys_item_selected.gif) no-repeat right bottom;
                bottom: 2px;
                display: none;
                font-size: 0;
                height: 10px;
                line-height: 0;
                position: absolute;
                right: 1px;
                width: 10px;
                z-index: 99;
            }

            .sys_spec_text li.selected a {
                border: 1px solid #4A5B79;
                padding: 0 0px;
            }

            .sys_spec_text li.selected .check {
                display: block;
            }

            .sys_spec_text li img {
                border: 0px solid #fff;
                margin-top: -2px;
                padding-right: 5px;
                vertical-align: middle;
            }

        .sys_spec_text a.disabled {
            color: #a9a6a6;
            cursor: not-allowed;
            display: block;
            overflow: hidden;
        }
</style>
@using EIP.Common.Entities.Dtos
@using EIP.Web.AdminLTE.DataUsers.Helpers
 
    <section class="content" id="mainDiv">
        <div class="row">
            <div class="col-md-4">
                <div class="box box-primary box-solid">
                    <div class="box-header with-border">
                        <h3 class="box-title">模块</h3>
                        <div class="box-tools pull-right">
                            <a href="javascript:void(0);" onclick=" arrowin(); return false; " data-toggle="tooltip" title="展开" class="btn btn-default btn-sm"><i class="fa fa-folder-open" id="arrowin">展开</i></a>
                        </div>
                    </div>
                    <div class="box-body">
                        @*工具条*@
                        <ul id="functionTree" class="ztree" style="height: 370px; overflow: auto"></ul>
                    </div>
                </div>
            </div>
            <div class="col-md-8">
                <div class="box box-primary box-solid">
                    <div class="box-header with-border">
                        <h3 class="box-title">模块按钮</h3>
                        <div class="box-tools">
                            <a href="javascript:void(0);" onclick=" selectall(); return false; " data-toggle="tooltip" title="全选" class="btn btn-default btn-sm"><i class="fa fa-check-circle-o" id="select">全选</i></a>
                        </div>
                    </div>
                    <div class="box-body no-padding">
                        @*所有功能性按钮*@
                        <div style="height: 383px;" class="ScrollBar">
                            @Html.MessageBox(new MessageBoxInput()
                                        {
                                            HtmlAttributes = " width='305'",
                                            MessageBoxType = EnumMessageBoxType.info,
                                            Msg = "点击左侧菜单查看模块按钮信息"
                                        })
                            <ul id="AccessButton" class="sys_spec_text" style="display: none">
                                @{
                                    foreach (var m in Model)
                                    {
                                        <li title="@m.Name" modelid="@m.MenuId" style="display: none" class="@m.Remark">
                                            <a style="color: #000;" id="@m.DataId">
                                                @m.Name
                                            </a><i class="check"></i>
                                        </li>
                                    }
                                }

                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </section>
    <div class="box-footer text-right">
        <!--以下两种方式提交验证,根据所需选择-->
        <button onclick=" formSubmit(); return false; " type="button" class="btn btn-success" data-btn-type="save" title="确定"><span class="bootstrap-dialog-button-icon fa fa-check"></span>确定</button>
        <button type="button" class="btn btn-danger" data-btn-type="cancel" data-dismiss="modal"><span class="bootstrap-dialog-button-icon fa fa-times"></span>取消</button>
    </div>
    @Html.Hidden("privilegeMasterValue")
    @Html.Hidden("privilegeMaster")
    <script>
        $(function () {
            initEvent();
            initFunctionTreeData();
        });

        var functionZNodes, //模块按钮节点
            functionTreeObj, //模块按钮树对象
            functionSetting; //功能性树设置

        //初始化事件
        function initEvent() {
            $("#AccessButton li").click(function () {
                if (!$(this).hasClass("selected")) {
                    $(this).attr("class", "selected");
                } else {
                    $(this).attr("class", "");
                }
            });
        }

        //初始化菜单
        function initFunctionMenuTree() {
            //配置
            functionSetting = {
                view: {
                    dblClickExpand: false,
                    showLine: true
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                },
                callback: {
                    onClick: function (e, treeId, treeNode) {
                        //隐藏提示
                        $(".messagebox").hide();
                        $("#AccessButton").show();
                        checkAll = true;
                        $("#AccessButton li").hide();
                        var modelidlength = $("li[modelid='" + treeNode.id + "']").length;
                        if (modelidlength > 0) {
                            $("li[modelid='" + treeNode.id + "']").show();
                        } else {
                            $(".msg-content").html("<strong style=\"font-size: 14px\">【" + treeNode.name + "】无模块按钮权限</strong>");
                            $(".messagebox").show();
                        }

                    }
                }
            };
            functionTreeObj = $.fn.zTree.init($("#functionTree"), functionSetting, functionZNodes);
        }

        //初始化树结构
        function initFunctionTreeData() {
            UtilAjaxPost("/System/Permission/GetMenuHavePermissionByPrivilegeMasterValue", {
                privilegeMasterValue: $("#privilegeMasterValue").val(),
                privilegeMaster: $("#privilegeMaster").val(),
                PrivilegeAccess: Language.privilegeAccess.data //模块按钮
            }, function (data) {
                functionZNodes = data;
                initFunctionMenuTree();
            });
        }



        //折叠/展开
        var expand = false;

        function arrowin() {
            if (expand) {
                functionTreeObj.expandAll(false);
                expand = false;
                $("#arrowin").html("展开").attr("class", "fa fa-folder-open");
                $("#arrowin").parent().attr("title", "展开");
            } else {
                functionTreeObj.expandAll(true);
                expand = true;
                $("#arrowin").html("折叠").attr("class", "fa fa-folder");
                $("#arrowin").parent().attr("title", "折叠");
            }
        }

        //全选/重置
        var checkAll = true;

        function selectall() {
            var treeNode = ZtreeGetSelectedNodes($.fn.zTree.getZTreeObj("functionTree"));
            if (treeNode.length === 0) {
                DialogTipsMsgWarn("请选择菜单", 1000);
                return;
            }
            var $module = $("li[modelid='" + treeNode[0].id + "']");
            if (checkAll) {
                $module.attr("class", "selected");
                checkAll = false;
            } else {
                $module.attr("class", "");
                checkAll = true;
            }
        }

        //表单提交
        function formSubmit() {
            DialogTipsMsgWait("正在处理中");
            var json = "";
            var $function = $("li[class='selected']").find("a");
            $.each($function, function (i, item) {
                json += "{\"P\":\"" + item.id + "\"},";
            });
            json = json.substring(0, json.length - 1);
            json = "[" + json + "]";
            UtilAjaxPostWait("/System/Permission/SavePermission", {
                privilegeAccess: Language.privilegeAccess.data, //模块按钮
                privilegeMasterValue: $("#privilegeMasterValue").val(),
                privilegeMaster: $("#privilegeMaster").val(),
                menuPermissions: json //权限json字符串
            }, function (data) {
                DialogAjaxResult(data);

            });
        }
    </script>
